package com.itheima.controller;

import com.itheima.job.MyTask2;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

@RestController
public class TestTaskController {

    @Resource
    private MyTask2 myTask2;

    @GetMapping(value = "/testTask")
    public String testTask(){

        long start = System.currentTimeMillis();

        Future<String> f1= myTask2.task1();
        Future<String> f2=myTask2.task2();
        Future<String> f3=myTask2.task3();

        while (true){
            if(f1.isDone() &&f2.isDone()&&f3.isDone() ){
                break;
            }
        }
        long end = System.currentTimeMillis();

        System.out.println("任务总耗时："+(end-start));

        return "ok";

    }
}


